package com.cyandpos.pad.cateringformat.choosemenu;

import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.cyandpos.pad.R;
import com.cyandpos.pad.activity.BaseActivity;
import com.cyandpos.pad.activity.MyHandler;
import com.cyandpos.pad.activity.PayActivity;
import com.cyandpos.pad.cateringformat.CateringMainActivity;
import com.cyandpos.pad.common.commondata.Constant;
import com.cyandpos.pad.common.commondata.DialogConstant;
import com.cyandpos.pad.common.commondata.ErpCommonData;
import com.cyandpos.pad.common.commondata.OnDialogListener;
import com.cyandpos.pad.posdata.QueryMemberReq;
import com.cyandpos.pad.posdata.TicketInfo;
import com.cyandpos.pad.presentation.AdPresentationUtil;
import com.cyandpos.pad.sale.saleutils.SaleUtil;
import com.cyandpos.pad.sale.saleutils.TimeThread;
import com.cyandpos.pad.utils.CommonUtils;
import com.squareup.picasso.NetworkPolicy;
import com.squareup.picasso.Picasso;

import butterknife.BindView;

public class MenuFoodActivity extends BaseActivity {

    @BindView(R.id.container_catering_main)
    FrameLayout containerCateringMain;
    @BindView(R.id.iv_catering_main_project_logo)
    ImageView ivCateringMainProjectLogo;
    @BindView(R.id.tv_catering_main_storeName)
    TextView tvCateringMainStoreName;
    @BindView(R.id.tv_catering_main_title_version)
    TextView tvCateringMainTitleVersion;
    @BindView(R.id.tv_catering_main_title_cashier)
    TextView tvCateringMainTitleCashier;
    @BindView(R.id.tv_catering_main_title_sktno)
    TextView tvCateringMainTitleSktno;
    @BindView(R.id.tv_catering_main_title_orderno)
    TextView tvCateringMainTitleOrderno;
    @BindView(R.id.tv_catering_main_title_currentTime)
    public TextView tvCateringMainTitleCurrentTime;
    @BindView(R.id.iv_catering_main_wifi)
    ImageView ivCateringMainWifi;
    @BindView(R.id.iv_catering_main_printer)
    ImageView ivCateringMainPrinter;
    @BindView(R.id.iv_catering_main_exist)
    ImageView ivCateringMainExist;
    private MenuFoodFragment menuFoodFragment;
    public AdPresentationUtil adPresentationUtil;
    private final MyHandler handler = new MyHandler(this);
    @Override
    protected void initData() {
        adPresentationUtil=new AdPresentationUtil();
        adPresentationUtil.initDisplayData(this);
        String tablePerson=getIntent().getStringExtra("tablePerson");
        String tableNo=getIntent().getStringExtra("tableNo");
        int tableState=getIntent().getIntExtra("tableState",-2);
        int fromType=getIntent().getIntExtra("fromType",0);
        TicketInfo mTicketInfo = ErpCommonData.ticketInfo;
        if(fromType==1) {
            mTicketInfo.setTableNo(tableNo);
            mTicketInfo.setTablePerson(tablePerson);
            mTicketInfo.setTableState(tableState);
        }
        menuFoodFragment=new MenuFoodFragment();
        getSupportFragmentManager().beginTransaction().replace(R.id.container_catering_main,menuFoodFragment).commit();
        ivCateringMainExist.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showBackDialog();
            }
        });
        initTitleData();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_menu_food;
    }

    public void queryMember(QueryMemberReq requestParam){
        menuFoodFragment.queryMember(requestParam);
    }

    private void showBackDialog() {
        String titleMsg = "是否退出?";
        String messageMsg ="是否退出下单?";
        SaleUtil.showInfoDialog(MenuFoodActivity.this, titleMsg, messageMsg, new OnDialogListener() {
            @Override
            public void onClick(int flag) {
                if(flag== DialogConstant.DIALOG_BTN_SURE) {
                    //menuFoodFragment.cancleOrder();
                    menuFoodFragment.finish();
                }
            }
        });
    }

    private void initTitleData() {
        tvCateringMainTitleVersion.setText(CommonUtils.getCurrentVersionName(MenuFoodActivity.this));
        tvCateringMainTitleCashier.setText(ErpCommonData.loadConfig.getCashierName() + "");
        tvCateringMainTitleSktno.setText(ErpCommonData.sktno + "");
        Picasso.get().load(R.mipmap.shiji_log1).
                networkPolicy(NetworkPolicy.NO_CACHE, NetworkPolicy.NO_STORE)
                .placeholder(R.mipmap.shiji_log1).error(R.mipmap.shiji_log1)
                .into(ivCateringMainProjectLogo);
        TimeThread timeThread = new TimeThread(handler, Constant.CATERING_MAIN_UPDATE_CURRENT_TIME_HANDLEID);
        timeThread.setDaemon(true);//守护线程
        timeThread.start();
    }

    public void setOrderNo(String orderNo){
        tvCateringMainTitleOrderno.setText(orderNo);
    }
}
